package com.risetechnology.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class SmartSharedPreferrence {

	private static SharedPreferences sharedPrefs;
	private static SharedPreferences.Editor editor;

	private static final String PREF_KEY_SHOW_FIRST_INTRO = "show_first_intro";
	private static final String PREF_KEY_SHOW_SECOND_INTRO = "show_second_intro";
	private static final String PREF_KEY_MAIL_ADDRESS = "mail_address";

	public static void setMailAddress(Context context, int ID, String mailAddress) {
		if (sharedPrefs == null) {
			sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		}
		if (editor == null) {
			editor = sharedPrefs.edit();
		}
		
		if (editor != null) {
			editor.putString(PREF_KEY_MAIL_ADDRESS + ID, mailAddress);
			editor.commit();
		}
	}

	public static String getMailAddress(Context context, int ID) {
		if (sharedPrefs == null) {
			sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		}
		
		return sharedPrefs.getString(PREF_KEY_MAIL_ADDRESS + ID, "");
	}
	
	public static void setFirstShowIntro(Context context, boolean isShown) {
		if (sharedPrefs == null) {
			sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		}
		if (editor == null) {
			editor = sharedPrefs.edit();
		}
		
		if (editor != null) {
			editor.putBoolean(PREF_KEY_SHOW_FIRST_INTRO, isShown);
			editor.commit();
		}
	}

	public static boolean getShowFirstIntro(Context context) {
		if (sharedPrefs == null) {
			sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		}
		
		boolean isShown = sharedPrefs.getBoolean(PREF_KEY_SHOW_FIRST_INTRO, true);

		return isShown;
	}
	
	public static void setShowSecondIntro(Context context, boolean isShown) {
		if (sharedPrefs == null) {
			sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		}
		if (editor == null) {
			editor = sharedPrefs.edit();
		}
		
		if (editor != null) {
			editor.putBoolean(PREF_KEY_SHOW_SECOND_INTRO, isShown);
			editor.commit();
		}
	}

	public static boolean getShowSecondIntro(Context context) {
		if (sharedPrefs == null) {
			sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		}
		
		boolean isShown = sharedPrefs.getBoolean(PREF_KEY_SHOW_SECOND_INTRO, true);

		return isShown;
	}
}
